package com.wtwd.device.controller;


import com.wtwd.device.model.entity.WeeklySportInfo;
import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.service.WeeklySportInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mjy
 * @since 2022-04-25
 */
@Api(tags = "周报模块")
@RestController
@RequestMapping("/weekly-sport-info")
public class WeeklySportInfoController {

    private static final Logger logger = LoggerFactory.getLogger(WeeklySportInfoController.class);


    @Autowired
    private WeeklySportInfoService weeklySportInfoService;

    /**
     *
     */
    /**
     * 根据起始时间查询用户所有周报
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "根据用户查询用户的运动数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = false, dataType = "String"),
    })
    @GetMapping("/getUserAllWeekly")
    private ResultVO<List<WeeklySportInfo>> getUserWeekly(
            @RequestParam(value = "userId", required = true) Long userId,
            @RequestParam(value = "startTime", required = false) String startTime,
            @RequestParam(value = "endTime", required = false) String endTime

    ) {
        logger.info("getUserWeekly userId={},startTime={},endTime={}", userId, startTime, endTime);
        List<WeeklySportInfo> weeklySportInfos = weeklySportInfoService.getUserWeekly(userId, startTime, endTime);
        return ResultVO.success(weeklySportInfos);
    }

    /**
     * 批量添加
     */
    @ApiOperation(value = "批量添加周报")
    @PostMapping("/bathAddWeekly")
    private ResultVO bathAddWeekly(@RequestBody List<WeeklySportInfo> weeklySportInfos) {
        logger.info("bathAddWeekly param={}", weeklySportInfos);
        Integer rest = weeklySportInfoService.bathAddWeekly(weeklySportInfos);
        if (rest > 0) {
            return ResultVO.success();
        } else {
            return ResultVO.error();
        }
    }


}

